package com.codingapi.auto.deploy.controller;

import com.codingapi.auto.deploy.service.DeployService;
import com.codingapi.auto.deploy.service.EmailNotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author modificial
 * @date 2018/7/23
 * @company codingApi
 * @description 码云回调，进行单元测试
 */
@RestController
@RequestMapping("/auto/deploy")
public class DeployController {
    @Autowired
    private DeployService deployService;
    @Autowired
    private EmailNotifyService emailNotifyService;

    @PostMapping("/execute")
    public boolean deploy() {
        List<String> message = deployService.deploy();
        StringBuilder stringBuilder = new StringBuilder();
        message.forEach(stringBuilder::append);
        emailNotifyService.sendHtmlEmail(stringBuilder.toString(), true);
        return true;
    }
}
